<template>
  <div>
    <div class="layout-header" style="float:left">

      <el-button
        type="primary"
        icon="el-icon-plus"
        style="margin-left:0px"
        @click="changeEdit(0)"
      >添加</el-button>

    </div>

    <div class="layout-content">
      <el-table
        :data="navData"
        stripe
        align="center"
        highlight-current-row
        style="width: 100%;margin-top:50px"
        :cell-class-name="cellClassName"
      >
        <el-table-column align="center" prop="text" label="导航名" />
        <el-table-column align="center" prop="title" label="页首标题" />
        <el-table-column align="center" prop="pagePath" label="跳转地址" />
        <el-table-column align="center" prop="sort" label="排序" />
        <el-table-column align="center" prop="classFont" label="图标">
          <template slot-scope="scope">
            <i v-if="scope.row.isUsePic == 0" :class="scope.row.classFont" style="font-size:30px;" />
            <img v-else style="width:30px;" :src="scope.row.iconPath">
          </template>
        </el-table-column>

        <el-table-column align="center" label="是否使用图片">
           <template slot-scope="scope">
            <el-button size="mini" :type="scope.row.isUsePic === 1 ? 'primary' : 'success'" @click="change_status(scope.row.id,'isUsePic' ,scope.row.isUsePic)">
              {{ scope.row.isUsePic === 1 ? "是" : "否" }}
            </el-button>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="status" label="是否启用" width="80">
          <template slot-scope="scope">
            <el-button size="mini" :type="scope.row.status === 1 ? 'primary' : 'success'" @click="change_status(scope.row.id,'status' ,scope.row.status)">
              {{ scope.row.status === 1 ? "是" : "否" }}
            </el-button>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="telephone"
          width="80"
          label="操作"
        >
          <template slot-scope="scope">
            <el-button type="warning" size="mini" icon="el-icon-edit" @click="changeEdit(scope.row.id)" />
            <!-- <el-button
              type="danger"
              size="small"
              icon="el-icon-delete"
              @click="onDel(scope.row.id)"
            /> -->
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page="current_page"
      :page-size="per_page"
     layout="total, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>

export default {
  name: 'TabbarEdit',
  data() {
    return {
      value: '',
      searchWhere: {
        title: ''
      },
      navData: [],
      total: 0,
      current_page: 1,
      per_page: 14
    }
  },
  mounted() {
    this.onSearch()
  },
  methods: {
    changeEdit(id) {
      this.$store.commit('user/SET_EDITID',id)
      this.$store.commit('user/SET_EDIT',13)
    },
    // 图标class绑定
    cellClassName({ row, column, rowIndex, columnIndex }) {
      if (column.property === 'iconPath') {
        return row.iconPath
        //  console.log(row)
      }
      // if(this.isSetSpecialColor) { // 这个是flag字段，标识是否显示特殊颜色，true,false
      //     // if(column.property != "filetypeName" && column.property != "fileName" && column.property != "updateTime") { // filetypeName...这些都是表格字段
      //     //     let columnProperty = this.tableData[rowIndex][column.property];
      //     //     if(columnProperty == 0) {
      //     //         return 'greenClass' // class名称
      //     //     } else if(columnProperty == 1) {
      //     //         return 'orangeClass'; // class名称
      //     //     } else if(columnProperty == 2) {
      //     //         return 'redClass' // class名称
      //     //     } else if(columnProperty == '' || columnProperty == null) {
      //     //         return 'emptyClass' // class名称
      //     //     }
      //     // }
      // }
    },
    // 查询
    handleSizeChange(val) {
      this.onSearch()
    },
    handleCurrentChange(val) {
      this.current_page = val
      this.onSearch()
    },
    onSearch() {
      const form = {}
      form.page = this.current_page
      form.map = this.searchWhere
      // 获取底部导航菜单
      this.get('/admin/BottomTab/index', form, 'POST').then(e => {
        this.navData = e.list.data
        this.per_page = e.list.per_page
        this.total = e.list.total
        this.current_page = e.list.current_page
        console.log(e)
      })
    },
    // 添加
    onAdd() {},
    // 编辑
    onEdit(id) {
      console.log(id)
    },
    // 修改状态
    change_status(id, field, val) {
      this.update(id, val, field, 'BottomTab').then(e => {
        e ? this.onSearch() : ''
      })
    }
    // 删除
    // onDel(id) {
    //   this.$msg_confirm().then(e => {
    //     if (e) {
    //       this.get('/admin/BottomTab/del?id=' + id, this.form, 'POST').then(e => {
    //         this.onSearch()
    //       })
    //     }
    //   })
    // }
  }
}
</script>

<style>
.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
</style>>
